﻿

var str = '<div class=" parameter" >\
	<div class="prop_top">\
		<i>设备列表</i>\
		<a href="javascript:void(0)" class="close_icon close_img"><img src="../images/close_icon.png"></a>\
	</div>\
	<div class="bookdetail_box">\
		<div class="blank_div"></div>\
		<div class="blank_div"></div>\
		<div class="label_div">\
			<label class="text_label">设备名称：</label>\
			<input type="text" class="input_search" placeholder="" id="qry_device_name" />\
		</div>\
		<div class="label_div">\
			<label class="text_label">设备名称：</label>\
			<input type="text" class="input_search" placeholder="" id="qry_device_name" />\
		</div>\
		&nbsp;&nbsp;&nbsp;&nbsp;\
		<button class="btn_common2"  onclick="itemFormSubmit()">添加</button>\
		<div class="blank_div"></div>\
		<table  class="table_list">\
    		<tr>\
			<!-- <th width="6%">序号</th> -->\
				<th width="30%">设备名称</th>\
				<th width="25%">设备序列号</th>\
				<th width="30%">设备型号</th>\
				<th class="last_td">操作</th>\
			</tr>\
			<tbody id="device_list" >\
				<tr>\
					<td>参数1</td>\
					<td>paramter</td>\
					<td>paramter</td>\
					<td></td>\
				</tr>\
			</tbody>\
		</table>\
		<div class="blank_div"></div>\
		<div class="blank_div"></div>\
		<div class="blank_div"></div></div></div>';
(function($){
	$("#template").html(str);
	//document.write("<script language='javascript' src='common.js'></script>");
	//jQuery.getScript("../js/common.js");
	$(".close_img").click(function() {
		// 弹框关闭按钮 
		$(this).parent().parent().hide();
		//$(".opacity_div").hide();
	});
	
	device();
}
)(jQuery);
function device(){
         //$(".row").html("");
      $.ajax({
         url: '../device/qryDeviceList', 
         type: 'POST',
         async: false,
         traditional:true,
         data:{yema:1,length:500},
         dataType: 'json', 
         timeout: 10000, 
         error: function(){LQWarn('请求失败,请稍后重试');}, 
         success: function(result){
             if(result.resultCode==1000){
                 var items = result.returnObject.pageList;
                 console.log(items);
                 var item ;
                 var html="";
                 var commType= "";
                 if(items){
                    $.each(items,function(i){
                        item = items[i];
                        if ( item.commType ==1){
                            commType = "FBox";
                        }else if(item.commType ==2){
                            commType = "蓝牙";
                        }else
                            commType = "其他";
                        html+='<tr data-status ="'+ item.id+'"><td>'
						/*//+ (i+1+length*(result.returnObject.curPage-1))
						+ '</td><td>' */
						+ item.name
						+ '</td><td>' 
						+ item.serialNumber
						+ '</td><td>' 
						+ replaceNull(item.modelName)
						+'</td><td class="last_td">'
						+ '<a class="sel" title="选择" href="javascript:void(0);" onclick="selItem(this)"></a>'
						
						+ '</td></tr>';
                    });
                 }
                 $("#device_list").html(html);
             }
         }
     });
}


function selItem(obj){
	$(".close_img").click();
	var id = $(obj).parents("tr").attr("data-status");
	$("#deviceId").val(id);
	$("input[name='deviceName']").val($(obj).parents("tr").find("td").eq(0).text());
	
}